﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using BLL;
using BLL.Managers;
using BLL.Entities;

namespace CorporateGymManagementSystem
{
    /// <summary>
    /// Interaction logic for MalfunctionWindow.xaml
    /// </summary>
    public partial class AddMalfunctionWindow : Window
    {
        public AddMalfunctionWindow()
        {
            InitializeComponent();
        }

        private void sendButton_Click(object sender, RoutedEventArgs e)
        {
            

            subjectTextBox.Background = Brushes.White;
            contentTextBox.Background = Brushes.White;
            string subject = subjectTextBox.Text.Trim();
            string description = contentTextBox.Text.Trim();
            bool isValid = true;
            if (subjectTextBox.Text.Equals("Enter subject here.."))
            {
                subjectTextBox.Background = Brushes.Pink;
                isValid = false;
            }
            if (contentTextBox.Text.Equals("Enter description here.."))
            {
                contentTextBox.Background = Brushes.Pink;
                isValid = false;
            }
            if (isValid == true)
            {
                if (MalfunctionManager.Instance.AddMalfunction(subject, description) != -1)
                {
                    statusBar.Content = "Malfuntion Was Added!";
                    this.Close();
                }
                else
                {
                    statusBar.Content = "An Error Has Occured!";
                }
            }
            else
            {
                statusBar.Content = "You Must Fill All The Fields!";
            }
        }

        private void subjectTextBox_GotFocus(object sender, RoutedEventArgs e)
        {
            if (subjectTextBox.Text.Equals("Enter subject here.."))
            {
                subjectTextBox.Text = string.Empty;
                subjectTextBox.Foreground = new SolidColorBrush(Colors.Black);
            }
        }

        private void subjectTextBox_LostFocus(object sender, RoutedEventArgs e)
        {
            if (subjectTextBox.Text.Equals(string.Empty))
            {
                subjectTextBox.Text = "Enter subject here..";
                subjectTextBox.Foreground = new SolidColorBrush(Colors.Gray);
            }
        }

        private void contentTextBox_GotFocus(object sender, RoutedEventArgs e)
        {
            if (contentTextBox.Text.Equals("Enter description here.."))
            {
                contentTextBox.Text = string.Empty;
                contentTextBox.Foreground = new SolidColorBrush(Colors.Black);
            }
        }

        private void contentTextBox_LostFocus(object sender, RoutedEventArgs e)
        {
            if (contentTextBox.Text.Equals(string.Empty))
            {
                contentTextBox.Text = "Enter description here..";
                contentTextBox.Foreground = new SolidColorBrush(Colors.Gray);
            }
        }
    }
}
